package cn.zhixiangsingle.impl.supplier;

import cn.zhixiangsingle.config.DynamicDataSourceContextHolder;
import cn.zhixiangsingle.dao.site.SiteMapper;
import cn.zhixiangsingle.dao.supplier.IngredientSupplierMapper;
import cn.zhixiangsingle.date.DateUtils;
import cn.zhixiangsingle.entity.base.IsEmptyUtils;
import cn.zhixiangsingle.entity.base.site.SiteData;
import cn.zhixiangsingle.entity.base.site.vo.SiteVO;
import cn.zhixiangsingle.entity.supplier.dto.IngredientSupplierDTO;
import cn.zhixiangsingle.entity.supplier.vo.IngredientSupplierVO;
import cn.zhixiangsingle.pagination.MyStartEndUtil;
import cn.zhixiangsingle.service.supplier.IngredientSupplierService;
import cn.zhixiangsingle.web.responsive.IStatusMessage;
import cn.zhixiangsingle.web.responsive.ResultBean;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

/**
 * All rights Reserved, Designed By www.zhixiangyun.net
 *
 * @version V1.0
 * @Title: zhixiangpingtai
 * @Package cn.zhixiangsingle.impl.supplier
 * @Description: ${todo}
 * @author: hhp
 * @date: 2019/10/5 13:38
 * @Copyright: 2019 www.zhixiangyun.net Inc. All rights reserved.
 * 注意：本内容仅限于浙江智飨科技内部传阅，禁止外泄以及用于其他的商业目
 */
@Service(version = "1.0.0", interfaceClass = IngredientSupplierService.class)
public class IngredientSupplierServiceImpl implements IngredientSupplierService {
    private static final Logger logger = LoggerFactory
            .getLogger(IngredientSupplierServiceImpl.class);
    @Autowired
    private SiteMapper siteMapper;
    @Autowired
    private IngredientSupplierMapper ingredientSupplierMapper;
    /**
     *@描述
     *@参数 [ingredientSupplierDTO]
     *@返回值 cn.zhixiangsingle.web.responsive.ResultBean
     *@创建人 hhp
     *@创建时间 2019/11/11
     *@修改人和其它信息
     */
    @Override
    public ResultBean updateIngredientSupplier(IngredientSupplierDTO ingredientSupplierDTO) throws Exception {
        ResultBean resultBean = new ResultBean();
        /*StringBuffer stringBufferJson = new StringBuffer();
        InputStream stream = getClass().getClassLoader().getResourceAsStream("json/siteData.json");
        BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        String line;
        while ((line = br.readLine()) != null) {
            stringBufferJson.append(line);
        }
        JSONObject jobj = JSON.parseObject(stringBufferJson.toString());
        SiteData siteData = null;
        if(!IsEmptyUtils.isEmpty(jobj.get(ingredientSupplierDTO.getSdId().toString()))){
            siteData = JSON.parseObject(jobj.get(ingredientSupplierDTO.getSdId().toString()).toString(),SiteData.class);
        }
        String dataSourceName = "";
        if(!IsEmptyUtils.isEmpty(siteData)){
            dataSourceName = siteData.getDateSourceName();
        }
        if(!IsEmptyUtils.isEmpty(dataSourceName)) {
            logger.info("-" + dataSourceName + "-");
            DynamicDataSourceContextHolder.setDataSourceType(dataSourceName);

            ingredientSupplierMapper.updateByPrimaryKey(ingredientSupplierDTO);

            DynamicDataSourceContextHolder.setDataSourceType(null);
        }
        resultBean.setSuccess(true);
        resultBean.setResultCode(IStatusMessage.SystemStatus.SUCCESS.getCode());
        resultBean.setMsg(IStatusMessage.SystemStatus.SUCCESS.getMessage());*/
        return resultBean;
    }

    @Override
    public ResultBean addIngredientSupplier(IngredientSupplierDTO ingredientSupplierDTO) throws Exception {
        ResultBean resultBean = new ResultBean();
        ingredientSupplierDTO.setDeleteStatus("1");
        ingredientSupplierDTO.setFoundTime(DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
        /*if(!IsEmptyUtils.isEmpty(morningMeetingDTO.getSdIds())){
            StringBuffer msgStr = new StringBuffer();
            String[] sdIds = morningMeetingDTO.getSdIds().split(",");
            for(String sdId:sdIds){
                morningMeetingDTO.setSdId(Integer.parseInt(sdId));
                StringBuffer stringBufferJson = new StringBuffer();
                InputStream stream = getClass().getClassLoader().getResourceAsStream("json/siteData.json");
                BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
                String line;
                while ((line = br.readLine()) != null) {
                    stringBufferJson.append(line);
                }
                JSONObject jobj = JSON.parseObject(stringBufferJson.toString());
                SiteData siteData = null;
                if(!IsEmptyUtils.isEmpty(jobj.get(sdId))){
                    siteData = JSON.parseObject(jobj.get(sdId).toString(),SiteData.class);
                }
                String dataSourceName = "";
                if(!IsEmptyUtils.isEmpty(siteData)){
                    dataSourceName = siteData.getDateSourceName();
                }
                if(!IsEmptyUtils.isEmpty(dataSourceName)) {
                    logger.info("----" + dataSourceName + "----");
                    DynamicDataSourceContextHolder.setDataSourceType(dataSourceName);
                    morningMeetingMapper.insertSelective(morningMeetingDTO);
                }
            }
            DynamicDataSourceContextHolder.setDataSourceType(null);
            resultBean.setSuccess(true);
            resultBean.setResultCode(IStatusMessage.SystemStatus.SUCCESS.getCode());
            if(!IsEmptyUtils.isEmpty(msgStr)){
                resultBean.setMsg(IStatusMessage.SystemStatus.SUCCESS.getMessage()+"(其中"+msgStr+"已提交，请勿重复提交)");
            }else{
                resultBean.setMsg(IStatusMessage.SystemStatus.SUCCESS.getMessage());
            }
        }else{
            StringBuffer stringBufferJson = new StringBuffer();
            InputStream stream = getClass().getClassLoader().getResourceAsStream("json/siteData.json");
            BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
            String line;
            while ((line = br.readLine()) != null) {
                stringBufferJson.append(line);
            }
            JSONObject jobj = JSON.parseObject(stringBufferJson.toString());
            SiteData siteData = null;
            if(!IsEmptyUtils.isEmpty(jobj.get(morningMeetingDTO.getSdId().toString()))){
                siteData = JSON.parseObject(jobj.get(morningMeetingDTO.getSdId().toString()).toString(),SiteData.class);
            }
            String dataSourceName = "";
            if(!IsEmptyUtils.isEmpty(siteData)){
                dataSourceName = siteData.getDateSourceName();
            }
            if(!IsEmptyUtils.isEmpty(dataSourceName)) {
                logger.info("----" + dataSourceName + "--");
                DynamicDataSourceContextHolder.setDataSourceType(dataSourceName);
                morningMeetingMapper.insertSelective(morningMeetingDTO);
                resultBean.setSuccess(true);
                resultBean.setResultCode(IStatusMessage.SystemStatus.SUCCESS.getCode());
                resultBean.setMsg(IStatusMessage.SystemStatus.SUCCESS.getMessage());
                DynamicDataSourceContextHolder.setDataSourceType(null);
            }
        }*/
        return resultBean;
    }
    /**
     *@描述
     *@参数 [ingredientSupplierDTO]
     *@返回值 cn.zhixiangsingle.web.responsive.ResultBean
     *@创建人 hhp
     *@创建时间 2019/11/11
     *@修改人和其它信息
     */
    @Override
    public ResultBean findIngredientSupplierList(IngredientSupplierDTO ingredientSupplierDTO) throws Exception {
        ResultBean resultBean = new ResultBean();
        if(IsEmptyUtils.isEmpty(ingredientSupplierDTO.getPage())){
            ingredientSupplierDTO.setPage(1);
        }
        if (IsEmptyUtils.isEmpty(ingredientSupplierDTO.getLimit())){
            ingredientSupplierDTO.setLimit(10);
        }
        Integer page = ingredientSupplierDTO.getPage();
        Integer limit = ingredientSupplierDTO.getLimit();
        StringBuffer stringBufferJson = new StringBuffer();
        InputStream stream = getClass().getClassLoader().getResourceAsStream("json/siteData.json");
        BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        String line;
        while ((line = br.readLine()) != null) {
            stringBufferJson.append(line);
        }
        JSONObject jobj = JSON.parseObject(stringBufferJson.toString());

        List<Map<String,Object>> mainLPLs = Lists.newArrayList();
        Integer total = 0;
        int startNum = (page-1)*limit;
        int endNum = startNum+limit;
        ArrayList<Integer> totalAll = Lists.newArrayList();
        ingredientSupplierDTO.setId(-1);
        if(IsEmptyUtils.isEmpty(ingredientSupplierDTO.getSupplierName())){
            ingredientSupplierDTO.setSupplierName("s");
        }
        if(IsEmptyUtils.isEmpty(ingredientSupplierDTO.getRegistrationNumber())){
            ingredientSupplierDTO.setRegistrationNumber("r");
        }
        if(IsEmptyUtils.isEmpty(ingredientSupplierDTO.getDeleteStatus())){
            ingredientSupplierDTO.setDeleteStatus("1");
        }
        ingredientSupplierDTO.setExpireTime("e");
        ingredientSupplierDTO.setPromptTime("p");
        ingredientSupplierDTO.setPrincipalName("p");
        ingredientSupplierDTO.setPrincipalTel("p");
        ingredientSupplierDTO.setSupDocumentPhoto("s");
        ingredientSupplierDTO.setSuppAdress("s");
        if(!IsEmptyUtils.isEmpty(ingredientSupplierDTO.getSdIds())){
            String[] sdIds = ingredientSupplierDTO.getSdIds().split(",");
            StringBuffer stringBuffer = new StringBuffer();
            for(String sdId:sdIds){
                ingredientSupplierDTO.setSdId(Integer.parseInt(sdId));
                String dataSourceName = "";
                SiteData siteData = null;
                if(!IsEmptyUtils.isEmpty(jobj.get(sdId))){
                    siteData = JSON.parseObject(jobj.get(sdId).toString(),SiteData.class);
                }
                ingredientSupplierDTO.setPicturePrefix(siteData.getPicturePrefix());
                if(!IsEmptyUtils.isEmpty(siteData)){
                    dataSourceName = siteData.getDateSourceName();
                }
                if(!IsEmptyUtils.isEmpty(dataSourceName)){
                    if(IsEmptyUtils.isEmpty(stringBuffer)){
                        stringBuffer.append(sdId);
                    }else{
                        stringBuffer.append(","+sdId);
                    }
                    logger.info("--"+dataSourceName+"--");
                    DynamicDataSourceContextHolder.setDataSourceType(dataSourceName);
                    Integer totalStatus = ingredientSupplierMapper.findIngredientSupplierTotal(ingredientSupplierDTO);
                    total = total + totalStatus;
                    totalAll.add(totalStatus);
                }
            }
            ArrayList<ArrayList<Integer>> startEndNums = MyStartEndUtil.getStartEndArray(totalAll,startNum,endNum);
            String[] sourceNames = stringBuffer.toString().split(",");
            for(int i=0;i<startEndNums.size();i++){
                ingredientSupplierDTO.setSdId(Integer.parseInt(sourceNames[i]));
                SiteData siteData = JSON.parseObject(jobj.get(sourceNames[i]).toString(),SiteData.class);
                ingredientSupplierDTO.setPicturePrefix(siteData.getPicturePrefix());
                logger.info("--"+siteData.getDateSourceName()+"--");
                DynamicDataSourceContextHolder.setDataSourceType(siteData.getDateSourceName());
                ingredientSupplierDTO.setStart(startEndNums.get(i).get(0));
                ingredientSupplierDTO.setEnd(startEndNums.get(i).get(1)-startEndNums.get(i).get(0));
                ingredientSupplierDTO.setSdId(Integer.parseInt(sourceNames[i]));
                ingredientSupplierDTO.setSiteName(siteData.getName());
                ingredientSupplierDTO.setSitePhoto(siteData.getPhoto());

                List<Map<String,Object>> mainLPList = ingredientSupplierMapper.findIngredientSupplierList(ingredientSupplierDTO);
                mainLPLs.addAll(mainLPList);
            }
            DynamicDataSourceContextHolder.setDataSourceType(null);
        }else{
            List<SiteVO> userSites = siteMapper.findUserSites(ingredientSupplierDTO.getUserId());
            StringBuffer stringBuffer = new StringBuffer();
            for(SiteVO siteVO:userSites){
                ingredientSupplierDTO.setSdId(siteVO.getSdId());
                String dataSourceName = "";
                String sdIdStr = siteVO.getSdId().toString();
                SiteData siteData = null;
                if(!IsEmptyUtils.isEmpty(jobj.get(sdIdStr))){
                    siteData = JSON.parseObject(jobj.get(sdIdStr).toString(),SiteData.class);
                }
                ingredientSupplierDTO.setPicturePrefix(siteData.getPicturePrefix());
                if(!IsEmptyUtils.isEmpty(siteData)){
                    dataSourceName = siteData.getDateSourceName();
                }
                if(!IsEmptyUtils.isEmpty(dataSourceName)){
                    if(IsEmptyUtils.isEmpty(stringBuffer)){
                        stringBuffer.append(siteVO.getSdId());
                    }else{
                        stringBuffer.append(","+siteVO.getSdId());
                    }
                    logger.info("null sdIds...--"+dataSourceName+"----");
                    DynamicDataSourceContextHolder.setDataSourceType(dataSourceName);
                    Integer totalStatus = ingredientSupplierMapper.findIngredientSupplierTotal(ingredientSupplierDTO);
                    total = total + totalStatus;
                    totalAll.add(totalStatus);
                }
            }
            ArrayList<ArrayList<Integer>> startEndNums = MyStartEndUtil.getStartEndArray(totalAll,startNum,endNum);
            String[] sourceNames = stringBuffer.toString().split(",");
            for(int i=0;i<startEndNums.size();i++){
                SiteData siteData = JSON.parseObject(jobj.get(sourceNames[i]).toString(),SiteData.class);
                logger.info("--"+siteData.getDateSourceName()+"--");
                ingredientSupplierDTO.setPicturePrefix(siteData.getPicturePrefix());
                ingredientSupplierDTO.setSdId(Integer.parseInt(sourceNames[i]));
                DynamicDataSourceContextHolder.setDataSourceType(siteData.getDateSourceName());
                ingredientSupplierDTO.setStart(startEndNums.get(i).get(0));
                ingredientSupplierDTO.setEnd(startEndNums.get(i).get(1)-startEndNums.get(i).get(0));
                ingredientSupplierDTO.setSdId(Integer.parseInt(sourceNames[i]));
                ingredientSupplierDTO.setSiteName(siteData.getName());
                ingredientSupplierDTO.setSitePhoto(siteData.getPhoto());

                List<Map<String,Object>> mainLPList = ingredientSupplierMapper.findIngredientSupplierList(ingredientSupplierDTO);
                mainLPLs.addAll(mainLPList);
            }
            DynamicDataSourceContextHolder.setDataSourceType(null);
        }
        resultBean.setSuccess(true);
        resultBean.setResult(mainLPLs);
        resultBean.setTotal(total);
        resultBean.setResultCode(IStatusMessage.SystemStatus.SUCCESS.getCode());
        resultBean.setMsg(IStatusMessage.SystemStatus.SUCCESS.getMessage());
        return resultBean;
    }
    /**
     * @version V1.0
     * @Title: zhixiangpingtai
     * @Description:
     * @author: hhp
     * @param:  * @param ingredientSupplierDTO
     * @date: 2019/10/14 19:06
     */
    @Override
    public ResultBean findAll(IngredientSupplierDTO ingredientSupplierDTO) throws Exception {
        ResultBean resultBean = new ResultBean();
        StringBuffer stringBufferJson = new StringBuffer();
        InputStream stream = getClass().getClassLoader().getResourceAsStream("json/siteData.json");
        BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        String line;
        while ((line = br.readLine()) != null) {
            stringBufferJson.append(line);
        }
        JSONObject jobj = JSON.parseObject(stringBufferJson.toString());

        List<Map<String,Object>> mainLPLs = Lists.newArrayList();

        ArrayList<Integer> totalAll = Lists.newArrayList();
        ingredientSupplierDTO.setId(-1);
        if(IsEmptyUtils.isEmpty(ingredientSupplierDTO.getSupplierName())){
            ingredientSupplierDTO.setSupplierName("s");
        }
        if(IsEmptyUtils.isEmpty(ingredientSupplierDTO.getDeleteStatus())){
            ingredientSupplierDTO.setDeleteStatus("1");
        }
        ingredientSupplierDTO.setSupDocumentPhoto("s");
        if(!IsEmptyUtils.isEmpty(ingredientSupplierDTO.getSdIds())){
            String[] sdIds = ingredientSupplierDTO.getSdIds().split(",");
            for(String sdId:sdIds){
                ingredientSupplierDTO.setSdId(Integer.parseInt(sdId));
                String dataSourceName = "";
                SiteData siteData = null;
                if(!IsEmptyUtils.isEmpty(jobj.get(sdId))){
                    siteData = JSON.parseObject(jobj.get(sdId).toString(),SiteData.class);
                }
                ingredientSupplierDTO.setPicturePrefix(siteData.getPicturePrefix());
                if(!IsEmptyUtils.isEmpty(siteData)){
                    dataSourceName = siteData.getDateSourceName();
                }
                if(!IsEmptyUtils.isEmpty(dataSourceName)){
                    logger.info("--"+dataSourceName+"--");
                    DynamicDataSourceContextHolder.setDataSourceType(dataSourceName);

                    ingredientSupplierDTO.setPicturePrefix(siteData.getPicturePrefix());
                    logger.info("--"+siteData.getDateSourceName()+"--");
                    DynamicDataSourceContextHolder.setDataSourceType(siteData.getDateSourceName());

                    ingredientSupplierDTO.setSiteName(siteData.getName());
                    ingredientSupplierDTO.setSitePhoto(siteData.getPhoto());

                    List<Map<String,Object>> mainLPList = ingredientSupplierMapper.findIngredientSupplierList(ingredientSupplierDTO);
                    mainLPLs.addAll(mainLPList);

                }
            }
            DynamicDataSourceContextHolder.setDataSourceType(null);
        }else{
            List<SiteVO> userSites = siteMapper.findUserSites(ingredientSupplierDTO.getUserId());
            StringBuffer stringBuffer = new StringBuffer();
            for(SiteVO siteVO:userSites){
                String dataSourceName = "";
                String sdIdStr = siteVO.getSdId().toString();
                SiteData siteData = null;
                if(!IsEmptyUtils.isEmpty(jobj.get(sdIdStr))){
                    siteData = JSON.parseObject(jobj.get(sdIdStr).toString(),SiteData.class);
                }
                ingredientSupplierDTO.setSdId(siteVO.getSdId());
                ingredientSupplierDTO.setPicturePrefix(siteData.getPicturePrefix());
                if(!IsEmptyUtils.isEmpty(siteData)){
                    dataSourceName = siteData.getDateSourceName();
                }
                if(!IsEmptyUtils.isEmpty(dataSourceName)){

                    logger.info("--"+siteData.getDateSourceName()+"--");
                    ingredientSupplierDTO.setPicturePrefix(siteData.getPicturePrefix());

                    DynamicDataSourceContextHolder.setDataSourceType(siteData.getDateSourceName());

                    ingredientSupplierDTO.setSiteName(siteData.getName());
                    ingredientSupplierDTO.setSitePhoto(siteData.getPhoto());

                    List<Map<String,Object>> mainLPList = ingredientSupplierMapper.findIngredientSupplierList(ingredientSupplierDTO);
                    mainLPLs.addAll(mainLPList);
                }
            }
            DynamicDataSourceContextHolder.setDataSourceType(null);
        }
        resultBean.setSuccess(true);
        resultBean.setResult(mainLPLs);
        resultBean.setResultCode(IStatusMessage.SystemStatus.SUCCESS.getCode());
        resultBean.setMsg(IStatusMessage.SystemStatus.SUCCESS.getMessage());
        return resultBean;
    }
    /**
     *@描述
     *@参数 [ingredientSupplierDTO]
     *@返回值 java.util.List<cn.zhixiangsingle.web.responsive.ResultBean>
     *@创建人 hhp
     *@创建时间 2019/11/11
     *@修改人和其它信息
     */
    @Override
    public List<ResultBean> getIngredientSuppliers(IngredientSupplierDTO ingredientSupplierDTO) throws Exception {
        StringBuffer stringBufferJson = new StringBuffer();
        InputStream stream = getClass().getClassLoader().getResourceAsStream("json/siteData.json");
        BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        String line;
        while ((line = br.readLine()) != null) {
            stringBufferJson.append(line);
        }
        JSONObject jobj = JSON.parseObject(stringBufferJson.toString());

        List<ResultBean> mainLPLs = Lists.newArrayList();

        if(IsEmptyUtils.isEmpty(ingredientSupplierDTO.getSupplierName())){
            ingredientSupplierDTO.setSupplierName("s");
        }
        if(IsEmptyUtils.isEmpty(ingredientSupplierDTO.getRegistrationNumber())){
            ingredientSupplierDTO.setRegistrationNumber("r");
        }
        if(IsEmptyUtils.isEmpty(ingredientSupplierDTO.getDeleteStatus())){
            ingredientSupplierDTO.setDeleteStatus("1");
        }
        ingredientSupplierDTO.setExpireTime("e");
        ingredientSupplierDTO.setPromptTime("p");
        ingredientSupplierDTO.setPrincipalName("p");
        ingredientSupplierDTO.setPrincipalTel("p");
        ingredientSupplierDTO.setSupDocumentPhoto("s");
        ingredientSupplierDTO.setSuppAdress("s");
        String exportTopTitle = "供应商基础资料信息-"+DateUtils.formatDate(new Date(),"yyyy-MM-dd")+"导出";
        if(!IsEmptyUtils.isEmpty(ingredientSupplierDTO.getSdIds())){
            String[] sdIds = ingredientSupplierDTO.getSdIds().split(",");
            for(String sdId:sdIds){
                ingredientSupplierDTO.setSdId(Integer.parseInt(sdId));
                String dataSourceName = "";
                SiteData siteData = null;
                if(!IsEmptyUtils.isEmpty(jobj.get(sdId))){
                    siteData = JSON.parseObject(jobj.get(sdId).toString(),SiteData.class);
                }
                if(!IsEmptyUtils.isEmpty(siteData)){
                    dataSourceName = siteData.getDateSourceName();
                }
                if(!IsEmptyUtils.isEmpty(dataSourceName)){
                    logger.info("--"+dataSourceName+"--");
                    DynamicDataSourceContextHolder.setDataSourceType(dataSourceName);

                    ingredientSupplierDTO.setSiteName(siteData.getName());

                    Map columnWidth = new HashMap();
                    columnWidth.put(0,9000);
                    columnWidth.put(1,7000);
                    columnWidth.put(2,4000);
                    columnWidth.put(3,4000);
                    columnWidth.put(4,3000);
                    columnWidth.put(4,5000);
                    columnWidth.put(4,12000);
                    List<List<String>> topTitles = Lists.newArrayList();
                    List<String> col0 = Lists.newArrayList();
                    List<String> col1 = Lists.newArrayList();
                    List<String> col2 = Lists.newArrayList();
                    List<String> col3 = Lists.newArrayList();
                    List<String> col4 = Lists.newArrayList();
                    List<String> col5 = Lists.newArrayList();
                    List<String> col6 = Lists.newArrayList();
                    col0.add(exportTopTitle);col0.add("供应商家信息");
                    col1.add(exportTopTitle);col1.add("注册号");
                    col2.add(exportTopTitle);col2.add("预警时间");
                    col3.add(exportTopTitle);col3.add("到期时间");
                    col4.add(exportTopTitle);col4.add("联系人");
                    col5.add(exportTopTitle);col5.add("联系人电话");
                    col6.add(exportTopTitle);col6.add("实际地址");
                    topTitles.add(col0);
                    topTitles.add(col1);
                    topTitles.add(col2);
                    topTitles.add(col3);
                    topTitles.add(col4);
                    topTitles.add(col5);
                    topTitles.add(col6);
                    ResultBean resultBean = new ResultBean();
                    resultBean.setMsg(siteData.getName());
                    resultBean.setObj(columnWidth);
                    List<IngredientSupplierVO> mainLPList = ingredientSupplierMapper.findAllIngredientSuppliers(ingredientSupplierDTO);
                    resultBean.setRows(topTitles);
                    resultBean.setResult(mainLPList);
                    mainLPLs.add(resultBean);

                }
            }
            DynamicDataSourceContextHolder.setDataSourceType(null);
        }else{
            List<SiteVO> userSites = siteMapper.findUserSites(ingredientSupplierDTO.getUserId());
            StringBuffer stringBuffer = new StringBuffer();
            for(SiteVO siteVO:userSites){
                ingredientSupplierDTO.setSdId(siteVO.getSdId());
                String dataSourceName = "";
                String sdIdStr = siteVO.getSdId().toString();
                SiteData siteData = null;
                if(!IsEmptyUtils.isEmpty(jobj.get(sdIdStr))){
                    siteData = JSON.parseObject(jobj.get(sdIdStr).toString(),SiteData.class);
                }

                if(!IsEmptyUtils.isEmpty(siteData)){
                    dataSourceName = siteData.getDateSourceName();
                }
                if(!IsEmptyUtils.isEmpty(dataSourceName)){

                    logger.info("--"+siteData.getDateSourceName()+"--");

                    DynamicDataSourceContextHolder.setDataSourceType(dataSourceName);

                    ingredientSupplierDTO.setSiteName(siteData.getName());

                    Map columnWidth = new HashMap();
                    columnWidth.put(0,9000);
                    columnWidth.put(1,7000);
                    columnWidth.put(2,4000);
                    columnWidth.put(3,4000);
                    columnWidth.put(4,3000);
                    columnWidth.put(4,5000);
                    columnWidth.put(4,12000);
                    List<List<String>> topTitles = Lists.newArrayList();
                    List<String> col0 = Lists.newArrayList();
                    List<String> col1 = Lists.newArrayList();
                    List<String> col2 = Lists.newArrayList();
                    List<String> col3 = Lists.newArrayList();
                    List<String> col4 = Lists.newArrayList();
                    List<String> col5 = Lists.newArrayList();
                    List<String> col6 = Lists.newArrayList();
                    col0.add(exportTopTitle);col0.add("供应商家信息");
                    col1.add(exportTopTitle);col1.add("注册号");
                    col2.add(exportTopTitle);col2.add("预警时间");
                    col3.add(exportTopTitle);col3.add("到期时间");
                    col4.add(exportTopTitle);col4.add("联系人");
                    col5.add(exportTopTitle);col5.add("联系人电话");
                    col6.add(exportTopTitle);col6.add("实际地址");
                    topTitles.add(col0);
                    topTitles.add(col1);
                    topTitles.add(col2);
                    topTitles.add(col3);
                    topTitles.add(col4);
                    topTitles.add(col5);
                    topTitles.add(col6);
                    ResultBean resultBean = new ResultBean();
                    resultBean.setMsg(siteData.getName());
                    resultBean.setObj(columnWidth);
                    List<IngredientSupplierVO> mainLPList = ingredientSupplierMapper.findAllIngredientSuppliers(ingredientSupplierDTO);
                    resultBean.setRows(topTitles);
                    resultBean.setResult(mainLPList);
                    mainLPLs.add(resultBean);
                }
            }
            DynamicDataSourceContextHolder.setDataSourceType(null);
        }
        return mainLPLs;
    }
}
